package net.hn.hnms.biz.project.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.hn.hnms.biz.project.domain.ContractInvoice;
import net.hn.hnms.biz.project.domain.ContractPayment;
import net.hn.hnms.biz.project.request.ContractInfoReq;
import net.hn.hnms.biz.project.request.ContractPaymentReq;
import net.hn.hnms.biz.project.service.ContractPaymentService;
import net.hn.hnms.biz.project.vo.ContractInfoVo;
import net.hn.hnms.biz.project.vo.ContractPaymentVo;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.core.web.controller.BaseController;
import net.hn.hnms.sys.common.log.annotation.Log;
import net.hn.hnms.sys.common.log.enums.BusinessType;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "结算信息", tags = {"结算信息"})
@RestController
@RequestMapping("/contract/payment")
public class ContractPaymentController extends BaseController {

    @Autowired
    private ContractPaymentService contractPaymentService;
    /**
     * 新增发票信息
     */
    @ApiOperation("新增结算信息")
    @SaCheckPermission("contract:payment:add")
    @PostMapping("/add")
    @Log(title = "新增结算信息", businessType = BusinessType.INSERT)
    public R<Void> add(@Validated @RequestBody ContractPaymentReq contractPaymentReq) {
        return toAjax(contractPaymentService.insert(contractPaymentReq));
    }

    /**
     * 删除结算信息
     */
    @ApiOperation("删除结算信息")
    @SaCheckPermission("contract:payment:delete")
    @ApiImplicitParam(name = "idList", value = "要删除的id值,用逗号间隔", required = true, allowMultiple = true, dataType = "String", paramType = "query")
    @PostMapping("delete")
    @Log(title = "删除结算信息", businessType = BusinessType.DELETE)
    public R<Void> delete(@RequestParam("idList") List<String> idList) {
        contractPaymentService.updateDeleteByIds(idList);
        return R.ok();
    }

    /**
     * 更新结算信息
     */
    @ApiOperation("更新结算信息")
    @SaCheckPermission("contract:payment:update")
    @PostMapping("/update")
    @Log(title = "更新结算信息", businessType = BusinessType.UPDATE)
    public R<Void> update(@Validated @RequestBody ContractPaymentReq contractPaymentReq) {
        contractPaymentService.updateById(contractPaymentReq);
        return R.ok();
    }

    /**
     * 结算信息详情
     */
    @ApiOperation("结算信息详情")
    @GetMapping("/{id}")
    public R<ContractPayment> detail(@PathVariable("id") String id) {
        return R.ok(contractPaymentService.selectDetailById(id));
    }

    /**
     * 结算信息列表
     */
    @ApiOperation("结算信息列表")
    @GetMapping("/page")
    public R<ResponsePage<ContractPaymentVo>> page(ContractPaymentReq contractPaymentReq, PageQuery pageQuery) {
        return R.ok(contractPaymentService.selectPageList(contractPaymentReq, pageQuery));
    }

    /**
     * 合同信息列表
     */
    @ApiOperation("合同信息列表")
    @GetMapping("/getContractPage")
    @AutoSetMineCode
    public R<ResponsePage<ContractInfoVo>> getContractPage(ContractInfoReq contractInfoReq, PageQuery pageQuery) {
        String contractTitle = contractInfoReq.getContractTitle();
        if(contractTitle != null){
            contractTitle = "%" + contractTitle + "%";
            contractInfoReq.setContractTitle(contractTitle);
        }
        return R.ok(contractPaymentService.selectContractPageList(contractInfoReq, pageQuery));
    }

    /**
     * 合同信息列表
     */
    @ApiOperation("发票下拉信息列表")
    @GetMapping("/getContractInvoiceList")
    @AutoSetMineCode
    public R<List<ContractInvoice>> getContractInvoiceList(ContractInfoReq contractInfoReq) {
        return R.ok(contractPaymentService.getContractInvoiceList(contractInfoReq));
    }



}
